package lnkwe.core.db;

import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;
import java.util.List;

//基本结果类型，包含系统是否正确返回，系统返回的对象
public class CommonResult<T> implements Serializable {

    private T result;
    private List<T> results;

    private ResultStatus status;
    private String message;

    private int startCount;
    private int count;
    private int totalCont;

    private Exception exception;

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public List<T> getResults() {
        return results;
    }

    public void setResults(List<T> results) {
        this.results = results;
    }

    public ResultStatus getStatus() {
        return status;
    }

    public void setStatus(ResultStatus status) {
        this.status = status;
    }


    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getStartCount() {
        return startCount;
    }

    public void setStartCount(int startCount) {
        this.startCount = startCount;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getTotalCont() {
        return totalCont;
    }

    public void setTotalCont(int totalCont) {
        this.totalCont = totalCont;
    }

    public Exception getException() {
        return exception;
    }

    public void setException(Exception exception) {
        this.exception = exception;
    }

    public JSONObject json() {
        JSONObject dataJSON = new JSONObject();
        if (status == ResultStatus.SUCCESS) {
            dataJSON.put("success",true);
            dataJSON.put("status", true);
        } else {
            dataJSON.put("status", false);
        }
        if (result != null) {
            dataJSON.put("model", result);
        }
        dataJSON.put("msg", this.getMessage());

        return dataJSON;
    }

}
